package com.bdqn.w.controller;

import com.alibaba.fastjson.JSON;
import com.bdqn.w.service.UserService;
import com.bdqn.w.utils.LayData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import com.bdqn.w.pojo.User;

@Controller
@RequestMapping(value = "/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping(value = "/toLogin.html")
    public String toLogin() {
        return "Login";
    }

    @RequestMapping(value = "/login")
    @ResponseBody
    public String Login(@RequestParam String username,
                        @RequestParam String password,
                        HttpSession session) {
        User user = userService.Login(username, password);
        if (user != null) {
            session.setAttribute("username", username);
            return JSON.toJSONString("true");
        } else {
            return JSON.toJSONString("false");
        }
    }

}
